import {reactive} from "@vue/composition-api";
import requestUrl from "../../api/requestUrl";
import { loadTableData } from "../../api/common";

export default function () {
  const tableData = reactive({
    item: [],
    total: 0
  });

  const tableLoadData = (requestParams) => {
    const requestData = {
      url: requestUrl[requestParams.url],
      method: requestParams.method,
      data: requestParams.data
    };

    loadTableData(requestData).then(res => {
      if (res && res.length > 0) {
        tableData.item = res;
        tableData.total = res.total;
      }
    });
  };

  return {
    tableData,
    tableLoadData
  }
};
